package cn.zwy.实战;

import java.io.IOException;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

public class ClassAllTypes {

    public static void main(String[] args) throws IOException {

        /*
         * Method[] methodArr = UserBean.class.getDeclaredMethods();
         * 
         * for (Method method : methodArr) {
         * System.out.println("--------------------------------------");
         * System.out.println(method.getName());
         * System.out.println(method.getReturnType().getName()); for (Class<?>
         * paramType : method.getParameterTypes()) {
         * System.out.println(paramType.getName()); }
         * System.out.println("--------------------------------------"); }
         * 
         * Field[] fieldArr = UserBean.class.getDeclaredFields(); for (Field
         * field : fieldArr) { System.out.println(field.getName() + " :  " +
         * field.getType().getName()); }
         */

        ClassReader cr = new ClassReader("cn.zwy.bean.UserBean");
        cr.accept(new ClassVisitor(Opcodes.ASM6) {
            @Override
            public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                    String[] exceptions) {
                MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
                final Type[] argTypes = Type.getArgumentTypes(desc);
                // System.out.println(name + " : " + argTypes.length);
                if (name.equals("getMax") || name.equals("setAmount")) {
                    return new MethodVisitor(Opcodes.ASM6) {
                        public void visitLocalVariable(String name, String desc, String signature,
                                org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) {
                            System.out.println(start + "," + end + "," + desc + " " + name +"," + index);
                        };
                    };
                }
                return mv;
            }

        }, 0);
    }

}
